﻿using System;
using System.Data;
using System.Data.SqlClient;
using EntitiesTM;

namespace DataAccess
{
    public class DaTimeDay
    {
        public DataTable selRegisterDay(string date, string email, string companyid)
        {
            string strCommandText = "selRegisterDay" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[2];
            paraLocal[0] = new SqlParameter("@Date", DateTime.Parse(date));
            paraLocal[1] = new SqlParameter("@Email", email);
            return SqlHelper.ExecuteData(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public int checkRegisterDay(string date, string email, string companyid)
        {
            string strCommandText = "checkRegisterDay" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[3];
            paraLocal[0] = new SqlParameter("@Date", DateTime.Parse(date));
            paraLocal[1] = new SqlParameter("@Email", email);
            paraLocal[2] = new SqlParameter("@Result", SqlDbType.SmallInt);
            paraLocal[2].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
            int intResult = int.Parse(paraLocal[2].Value.ToString());

            return intResult;
        }

        public DataTable selStaffIDByEmail(string email, string companyid)
        {
            string strCommandText = "selStaffIDByEmail" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[1];
            paraLocal[0] = new SqlParameter("@Email", email);
            return SqlHelper.ExecuteData(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public DataTable selRegisterByID(int SAID, string companyid)
        {
            string strCommandText = "selRegisterByID" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[1];
            paraLocal[0] = new SqlParameter("@SAID", SAID);
            return SqlHelper.ExecuteData(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public void updRegisterDay(EnSA sa, string companyid)
        {
            string strCommandText = "updRegisterDay" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[5];
            paraLocal[0] = new SqlParameter("@SAReportTimeHour", sa.saTimeReportHour);
            paraLocal[1] = new SqlParameter("@SAReportTimeMinute", sa.saTimeReportMinute);
            paraLocal[2] = new SqlParameter("@SADetails", sa.saDetails);
            paraLocal[3] = new SqlParameter("@SAID", sa.saID);
            paraLocal[4] = new SqlParameter("@SATypeTimeID", sa.saTypeTimeID);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public void updRegisterDay2(EnSA sa, string companyid)
        {
            string strCommandText = "updRegisterDayTmp" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[4];
            paraLocal[0] = new SqlParameter("@SAReportTimeHour", sa.saTimeReportHour);
            paraLocal[1] = new SqlParameter("@SAReportTimeMinute", sa.saTimeReportMinute);
            paraLocal[2] = new SqlParameter("@SADetails", sa.saDetails);
            paraLocal[3] = new SqlParameter("@SAID", sa.saID);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public void updRegisterDayFinish(EnSA sa, string companyid)
        {
            string strCommandText = "updRegisterDayFinish" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[3];
            paraLocal[0] = new SqlParameter("@Date", sa.saDate);
            paraLocal[1] = new SqlParameter("@Email", sa.email);
            paraLocal[2] = new SqlParameter("@SAIsFinish", sa.saIsFinish);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public void delRegisterDay(EnSA sa, string companyid)
        {
            string strCommandText = "delRegisterDay" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[1];
            paraLocal[0] = new SqlParameter("@SAID", sa.saID);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public void insRegisterDay(EnSA sa, string companyid)
        {
            string strCommandText = "insRegisterDay" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[7];
            paraLocal[0] = new SqlParameter("@SAReportTimeHour", sa.saTimeReportHour);
            paraLocal[1] = new SqlParameter("@SAReportTimeMinute", sa.saTimeReportMinute);
            paraLocal[2] = new SqlParameter("@SADetails", sa.saDetails);
            paraLocal[3] = new SqlParameter("@Email", sa.email);
            paraLocal[4] = new SqlParameter("@SAActivityID", sa.saActivityID);
            paraLocal[5] = new SqlParameter("@SADate", sa.saDate);
            paraLocal[6] = new SqlParameter("@SATypeTimeID", sa.saTypeTimeID);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public void insRegisterDay2(EnSA sa, string companyid)
        {
            string strCommandText = "insRegisterDayTmp" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[6];
            paraLocal[0] = new SqlParameter("@SAReportTimeHour", sa.saTimeReportHour);
            paraLocal[1] = new SqlParameter("@SAReportTimeMinute", sa.saTimeReportMinute);
            paraLocal[2] = new SqlParameter("@SADetails", sa.saDetails);
            paraLocal[3] = new SqlParameter("@Email", sa.email);
            paraLocal[4] = new SqlParameter("@SAActivityID", sa.saActivityID);
            paraLocal[5] = new SqlParameter("@SADate", sa.saDate);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public void insRegisterDayWeek(EnSA sa, string companyid)
        {
            string strCommandText = "insRegisterDayWeek" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[6];
            paraLocal[0] = new SqlParameter("@SAReportTimeHour", sa.saTimeReportHour);
            paraLocal[1] = new SqlParameter("@SAReportTimeMinute", sa.saTimeReportMinute);
            paraLocal[2] = new SqlParameter("@SADetails", sa.saDetails);
            paraLocal[3] = new SqlParameter("@Email", sa.email);
            paraLocal[4] = new SqlParameter("@SAActivityID", sa.saActivityID);
            paraLocal[5] = new SqlParameter("@SADate", sa.saDate);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public DataTable selRegisterWeekCopy(string date, string email, string companyid)
        {
            string strCommandText = "selRegisterWeekCopy"+companyid;
            SqlParameter[] paraLocal = new SqlParameter[2];
            paraLocal[0] = new SqlParameter("@Date", date);
            paraLocal[1] = new SqlParameter("@Email", email);
            return SqlHelper.ExecuteData(CommandType.StoredProcedure, strCommandText, paraLocal);
        }
    }
}
